package  com.ljb.android.component.nav.model

import android.graphics.Color
import com.ljb.android.component.nav.api.NavProtocol
import com.ljb.android.component.nav.bean.NavBean
import com.ljb.android.component.nav.contract.NavMainContract
import io.reactivex.rxjava3.core.Observable
import mvp.ljb.kt.model.BaseModel
import net.ljb.kt.HttpFactory
import kotlin.random.Random

/**
 * @Author Kotlin MVP Plugin
 * @Date 2021/02/24
 * @Description input description
 **/
class NavMainModel : BaseModel(), NavMainContract.IModel {

    override fun getNavData(): Observable<NavBean> {
        return HttpFactory.getProtocol(NavProtocol::class.java).getNvaTabList()
    }

    override fun handleColor(navBean: NavBean): NavBean {
        navBean.data.onEach { data ->
            data.articles.forEach { article ->
                val alpha = 255
                val red: Int = 55 + Random.nextInt(100)
                val green: Int = 55 + Random.nextInt(100)
                val blue: Int = 55 + Random.nextInt(100)
                val color = Color.argb(alpha, red, green, blue)
                article.color = color
            }
        }
        return navBean
    }
}